//接受web发送过来的返回事件
window.addEventListener("message", async function (event) {
    //处理页面响应的消息
    if (event.data.from === "web") {
        if (event.data.action == "localStorage_get") {
            await session.set("localStorage", event.data.data);
        }
    } else {

    }

});

let domain = ".oocl.com"
//接受worker.js popup.js
chrome.runtime.onMessage.addListener(async function (request, sender, sendResponse) {
    if (request.type == 'delCookie') {

        let dayTime = getDate(0).replace(/-/g, '');
        let hour = getCurrentTime().split(":")[0]
        let time = dayTime + hour;
        console.log(time)

        let message = {"from": "extenstion", "action": "localStorage_del"};
        window.postMessage(message, "*");
        sendMsg({action: 'delCookie', domain: domain})
        sendMsg({action: 'delCookie', domain: 'www'+domain})
    }
    if (request.type == 'setCookie') {
        let otherCache = JSON.parse(request.otherCache)
        let message = {"from": "extenstion", "action": "localStorage_set", data: otherCache['localStorage']};
        window.postMessage(message, "*");
        sendMsg({action: 'setCookie', data: otherCache['cookies']})
    }
    if (request.type == 'getCookie') {
        var message = {"from": "extenstion", "action": "localStorage_get"};
        window.postMessage(message, "*");
        sendMsg({action: 'getCookie', domain: domain})
        // sendMsg({action: 'getCookie', domain: domain, data: ['token']})
    }
    return true;
});